package managedbean.CI.Position;

import entity.Position;
import entity.Role;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.PositionSessionBeanLocal;

@ManagedBean(name="deletePositionManagerBean")
@ViewScoped
public class DeletePositionManagerBean implements Serializable
{
    @EJB
    private PositionSessionBeanLocal positionSessionBeanLocal;
    
    private Position positionToDelete;
    private List<Role> roles;

    public List<Role> getRoles() {   
        roles = (List<Role>)this.positionToDelete.getRoles();
        return roles; 
    }
        
    public Position getPositionToDelete() {
        return positionToDelete;
    }
    public void setPositionToDelete(Position positionToDelete) {
        this.positionToDelete = positionToDelete;
    }
    
    
    public DeletePositionManagerBean() {}
    
    public void initView(PhaseEvent event){
        if (positionToDelete == null)
        {
            positionToDelete = (Position) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedPosition");
        }
    }
    
    public void deletePosition(ActionEvent event)
    {
        System.out.println(""+ positionToDelete.getDescription());
                
        positionSessionBeanLocal.deletePosition(positionToDelete.getId());
    }   
    
}
